﻿Imports System.ExecutorServices
Imports System.Runtime.CompilerServices
Imports System.Aspect

Namespace Data.Objects

    Public Module SalesOrderLine

        <Item("SalesOrderLine", "sales order line")> Public Interface ISalesOrderLine
            <Field("SalesOrderLineID", "sales order line id")> Property SalesOrderLineID() As Integer
        End Interface

        <Aspect.PrimaryType(GetType(ISalesOrderLine))> _
        Public Interface ISalesOrderLineInfo
            Inherits ISalesOrderLine
            Inherits SalesOrder.ISalesOrder
            Inherits Product.IProduct
            <Field("Quantity", "quantity")> Property Quantity() As Decimal
        End Interface

        'DTO-style interface
        <Aspect.PrimaryType(GetType(ISalesOrderLine))> _
        Public Interface ISalesOrderLineFullInfo
            Inherits ISalesOrderLineInfo
            Inherits Customer.ICustomerInfo
            Inherits SalesOrder.ISalesOrderInfo
            Inherits Product.IProductInfo
        End Interface

        <Extension()> _
        Public Function AddSalesOrderLine(ByVal so As ISalesOrder, ByVal p As IProduct, ByVal qty As Decimal) As ISalesOrderLineInfo
            Return AddNew(so.SalesOrderID, p.ProductID, qty)
        End Function

        Private AddNew As dcGetNew = Aspect(Of dcGetNew)()
        <DataCall("AddANewSalesOrderLine", "add a new sales order line")> Private Delegate Function dcGetNew( _
        <Field("SalesOrderID", "sales order id")> ByVal SalesOrderID As Integer, _
        <Field("ProductID", "product id")> ByVal ProductID As Integer, _
        <Field("Quantity", "quantity")> ByVal quantity As Decimal _
        ) As ISalesOrderLineInfo

        Public GetAll As dcGetAll = Aspect(Of dcGetAll)()
        <DataCall("GetAllSalesOrderLines", "get all sales order lines")> Public Delegate Function dcGetAll() As ISalesOrderLineInfo()

        Public GetAllWithFullInfo As dcGetAllWithFullInfo = Aspect(Of dcGetAllWithFullInfo)()
        <DataCall("GetAllSalesOrderLineDTOs", "get all sales order line DTOs")> Public Delegate Function dcGetAllWithFullInfo() As ISalesOrderLineFullInfo()

        <Extension()> _
        Public Sub DeleteThisSalesOrderLine(ByVal s As ISalesOrderLine)
            _Delete(s.SalesOrderLineID)
        End Sub

        Private _Delete As dcDelete = Aspect(Of dcDelete)()
        <DataCall("DeleteSalesOrderLine", "delete a sales order line")> Private Delegate Sub dcDelete( _
        <Field("SalesOrderLineID", "sales order line id")> ByVal SalesOrderLineID As Integer)

    End Module

End Namespace